package com.huawei.appmarket.service.appmgr.view.activity.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.protocol.BaseListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.protocol.BaseListFragmentRequest;
import com.huawei.appmarket.R;
import com.huawei.appmarket.framework.widget.FixedSearchView;
import com.huawei.appmarket.service.appmgr.view.activity.AppInstallActivity;
import com.huawei.appmarket.service.launcher.FastAppInterceptor;
import com.huawei.appmarket.service.settings.view.widget.EnterLayout;
import com.huawei.fastengine.fastview.Config;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import o.azb;
import o.ced;
import o.cef;
import o.cep;
import o.cia;
import o.ciy;
import o.cjk;
import o.cjm;
import o.dgh;
import o.dgm;
import o.djp;
import o.Logger;
import o.dsm;
import o.dsp;
import o.dss;
import o.dsx;
import o.epr;
import o.eqp;
import o.evx;

@SuppressLint({"ValidFragment"})
public class ManagerFragment<T extends AppListFragmentProtocol> extends TaskFragment<T> implements ciy, dsp {
    private boolean ʹ = false;
    private ScrollView ʻˋ;
    private final c ʼ = new c(this);
    private com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment.c ʽ;
    protected boolean ˊ;
    protected d ˋ = d.INIT;
    protected long ˎ;
    protected boolean ˏ;
    protected long ॱ;
    private String ॱॱ;
    private int ᐝ;
    private Activity ﹳ = null;
    private e ﾞ = null;
    private boolean ﾟ = false;

    public static class b extends evx {
        String ˊ = eqp.ॱ();
        String ˋ = UserSession.getInstance().getUserId();
        WeakReference<ManagerFragment> ˎ;

        b(ManagerFragment managerFragment) {
            this.ˎ = new WeakReference(managerFragment);
        }

        public void ˋ(View view) {
            ManagerFragment managerFragment = (ManagerFragment) this.ˎ.get();
            if (managerFragment == null) {
                Logger.e("ManagerFragment", "onSingleClick, fragment == null");
                return;
            }
            Context ॱˋ = managerFragment.ॱˋ();
            if (ॱˋ == null) {
                Logger.e("ManagerFragment", "onSingleClick, activity == null");
                return;
            }
            switch (view.getId()) {
                case R.id.install_manager_layout:
                    dgh.ॱ(ॱˋ, "070606", "01|" + this.ˋ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊ);
                    managerFragment.ˎ(new Intent(ॱˋ, AppInstallActivity.class));
                    return;
                case R.id.apk_manager_layout:
                    dgh.ॱ(ॱˋ, ॱˋ.getString(R.string.bikey_apk_management_click), "01|" + this.ˋ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊ);
                    cjk.ˎ().ˋ(ॱˋ, new cjm("apkmgr.activity", null));
                    return;
                case R.id.fast_install_manager_layout:
                    dgh.ॱ(ॱˋ, "071506", "01|" + this.ˋ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊ);
                    managerFragment.ʽᐝ();
                    return;
                case R.id.system_manager_layout:
                    dgh.ॱ(ॱˋ, "071306", "01|" + this.ˋ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊ);
                    managerFragment.ॱ();
                    return;
                default:
                    return;
            }
        }
    }

    static class c extends Handler {
        private final WeakReference<ManagerFragment> ॱ;

        c(ManagerFragment managerFragment) {
            this.ॱ = new WeakReference(managerFragment);
        }

        public void handleMessage(Message message) {
            ManagerFragment managerFragment = (ManagerFragment) this.ॱ.get();
            if (managerFragment != null && managerFragment.ॱˋ() != null) {
                if (managerFragment.ʹ && managerFragment.ﾟ) {
                    managerFragment.ʿॱ();
                    managerFragment.ˊʼ();
                }
                dgh.onEvent(new o.dge.d(managerFragment.ॱˋ(), R.string.bikey_pm_brawse_time).ˏ(KeyAndValue.NUMBER_01).ˋ());
            }
        }
    }

    enum d {
        INIT,
        ONATTACT,
        ONSELECTED
    }

    public static class e {
        EnterLayout ˊ;
        EnterLayout ˋ;
        View ˎ;
        EnterLayout ˏ;
        EnterLayout ॱ;
    }

    public void ॱ(Activity activity) {
        ˎ(d.ONATTACT);
        super.ॱ(activity);
        this.ﹳ = activity;
        BaseListFragmentProtocol baseListFragmentProtocol = (BaseListFragmentProtocol) ˆ();
        if (!(baseListFragmentProtocol == null || baseListFragmentProtocol.ˎ() == null)) {
            BaseListFragmentRequest ॱ = ((AppListFragmentProtocol) ˆ()).ॱ();
            if (this.ˋ != d.ONSELECTED) {
                this.ˊ = ॱ.ˊˊ();
            }
            this.ᐝ = ॱ.ʻॱ();
            if (activity instanceof com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment.c) {
                this.ʽ = (com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.BaseListFragment.c) activity;
            }
        }
        if (Logger.ˎ()) {
            Logger.ˏ("ManagerFragment", "onAttach, AnalyticUtils, isSelected = " + this.ˊ + ", eventOrder = " + this.ˋ);
        }
    }

    public void ˏ(Bundle bundle) {
        ॱˋ(true);
        super.ˏ(bundle);
        if (this.ʽ != null) {
            cia ॱ = this.ʽ.ॱ(this.ᐝ);
            if (ॱ != null) {
                this.ॱॱ = ॱ.ʽ().getString("cache_expand_pkg");
            }
        }
    }

    public View ˋ(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Logger.ˎ("ManagerFragment", "onCreateView");
        View inflate = layoutInflater.inflate(R.layout.manager_fragment, viewGroup, false);
        this.ʻˋ = (ScrollView) inflate.findViewById(R.id.manage_scroll_view);
        FixedSearchView fixedSearchView = (FixedSearchView) inflate.findViewById(R.id.manager_search_bar);
        LinearLayout linearLayout = (LinearLayout) fixedSearchView.findViewById(R.id.search_bar);
        if (linearLayout != null) {
            linearLayout.setPadding(azb.ʻ(this.ﹳ), 0, azb.ॱॱ(this.ﹳ), 0);
        }
        fixedSearchView.setTabInfo("customColumn.managercenter", ॱ(R.string.install_manage));
        ˋ(inflate);
        ʼᐝ();
        dsm.ˏ().ˎ(hashCode() + "ManagerFragment", this);
        this.ﾟ = true;
        dsx.ˏ(o.dta.e.ˋ);
        return inflate;
    }

    private void ˎ(d dVar) {
        if (this.ˋ == d.INIT) {
            this.ˋ = dVar;
        }
    }

    private void ˋ(View view) {
        this.ﾞ = new e();
        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.update_card_manager_main_layout);
        View ˋ = dss.ॱ().ˋ(ॱˋ());
        linearLayout.addView(ˋ, -1, -2);
        this.ﾞ.ˎ = ˋ;
        if (!TextUtils.isEmpty(this.ॱॱ)) {
            dss.ॱ().ˊ(this.ﾞ.ˎ, this.ॱॱ);
        }
        boolean z = !djp.ˎ().ˊ() && dss.ॱ().ˋ(true, 1) > 0;
        dss.ॱ().ˎ(this.ﾞ.ˎ, z);
        this.ﾞ.ˋ = (EnterLayout) view.findViewById(R.id.install_manager_layout);
        this.ﾞ.ˋ.setTitle(Integer.valueOf(R.string.install_manager_title_ex));
        this.ﾞ.ˋ.setIcon(R.drawable.wisedist_manager_ins_nor);
        this.ﾞ.ˋ.setMemoVisibility(8);
        this.ﾞ.ˊ = (EnterLayout) view.findViewById(R.id.fast_install_manager_layout);
        this.ﾞ.ˊ.setTitle(Integer.valueOf(R.string.fast_app_manager_title));
        this.ﾞ.ˊ.setIcon(R.drawable.wisedist_manager_free_ins_nor);
        this.ﾞ.ˊ.setMemoVisibility(8);
        ˊʼ();
        this.ﾞ.ˏ = (EnterLayout) view.findViewById(R.id.system_manager_layout);
        this.ﾞ.ˏ.setTitle(Integer.valueOf(R.string.system_manager_title));
        this.ﾞ.ˏ.setIcon(R.drawable.wisedist_manager_clean_nor);
        this.ﾞ.ˏ.setMemoVisibility(8);
        this.ﾞ.ˏ.setNotEndLayout();
        this.ﾞ.ˏ.setLastLineGone();
        this.ﾞ.ॱ = (EnterLayout) view.findViewById(R.id.apk_manager_layout);
        this.ﾞ.ॱ.setTitle(Integer.valueOf(R.string.package_manager_title));
        this.ﾞ.ॱ.setIcon(R.drawable.wisedist_manager_ins_pac_nor);
        this.ﾞ.ॱ.setMemoVisibility(8);
    }

    private void ʼᐝ() {
        OnClickListener bVar = new b(this);
        this.ﾞ.ˋ.setOnClickListener(bVar);
        this.ﾞ.ˊ.setOnClickListener(bVar);
        this.ﾞ.ˏ.setOnClickListener(bVar);
        this.ﾞ.ॱ.setOnClickListener(bVar);
    }

    public boolean ˊ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        return false;
    }

    public void ˌ() {
        super.ˌ();
        ˉॱ();
        this.ˏ = true;
        if (this.ˊ) {
            this.ॱ = System.currentTimeMillis();
        }
    }

    public void ˋᐝ() {
        super.ˋᐝ();
        if (this.ˊ) {
            dgh.ˋ(ˊʻ(), ˌॱ());
            Logger.ˎ("ManagerFragment", "onPause, AnalyticUtils");
        }
        this.ˏ = false;
    }

    private void ʿॱ() {
        if (cep.ˏ(this.ﹳ, "huawei.intent.action.HSM_STORAGE_CLEANER") && cep.ˊ(this.ﹳ, "com.huawei.systemmanager")) {
            this.ﾞ.ˏ.setVisibility(0);
            return;
        }
        this.ﾞ.ˏ.setVisibility(8);
        this.ﾞ.ॱ.setNotEndLayout();
    }

    public void ॱ() {
        Logger.ˎ("ManagerFragment", "onClickSystemManager startResult=" + ced.ˋ(this.ﹳ, "com.huawei.systemmanager", null, cef.ˎ("com.huawei.systemmanager")));
    }

    private void ˊʼ() {
        if (eqp.ᐝ()) {
            this.ﾞ.ˊ.setVisibility(0);
        } else if (ˈॱ()) {
            this.ﾞ.ˊ.setVisibility(0);
        } else {
            this.ﾞ.ˊ.setVisibility(8);
        }
    }

    private boolean ˈॱ() {
        try {
            PackageInfo packageInfo = ॱˋ().getPackageManager().getPackageInfo(Config.FASTAPP_PACKAGE_NAME, 16);
            if (packageInfo == null || packageInfo.versionCode < 20000000) {
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public void ʽᐝ() {
        Logger.ˎ("ManagerFragment", "onClickFastInstallManager startResult=" + new FastAppInterceptor().launchManagerTab(this.ﹳ));
    }

    public void ᐝ() {
        super.ᐝ();
        this.ﾟ = false;
        dsm.ˏ().ˊ(hashCode() + "ManagerFragment");
        if (this.ﾞ.ˎ != null) {
            this.ॱॱ = dss.ॱ().ˊ(this.ﾞ.ˎ);
            cia ॱ = this.ʽ.ॱ(this.ᐝ);
            if (ॱ == null) {
                ॱ = new cia(ॱˋ());
            }
            ॱ.ʽ().putString("cache_expand_pkg", this.ॱॱ);
            this.ʽ.ˋ(this.ᐝ, ॱ);
        }
    }

    public void ˋ(int i) {
        ˎ(d.ONSELECTED);
        this.ʹ = true;
        ˉॱ();
        this.ˎ = dgh.ॱ();
        this.ˊ = true;
        if (this.ˏ) {
            this.ॱ = System.currentTimeMillis();
        }
        if (Logger.ˎ()) {
            Logger.ˏ("ManagerFragment", "onColumnSelected, AnalyticUtils, isSelected = " + this.ˊ + ", eventOrder = " + this.ˋ);
        }
    }

    public void ʽˊ() {
        this.ʹ = false;
        this.ʼ.removeMessages(105);
        if (this.ˎ > 0) {
            dgh.ˋ(ॱˋ(), "A04000", this.ˎ);
        } else {
            Logger.ˎ("ManagerFragment", "can not analytic display time");
        }
        if (this.ˏ) {
            dgh.ˋ(ˊʻ(), ˌॱ());
            if (Logger.ˎ()) {
                Logger.ˎ("ManagerFragment", "onColumnUnselected, AnalyticUtils");
            }
        }
        this.ˊ = false;
    }

    public void ʾॱ() {
        if (this.ʻˋ != null) {
            this.ʻˋ.post(new Runnable(this) {
                final /* synthetic */ ManagerFragment ˊ;

                {
                    this.ˊ = r1;
                }

                public void run() {
                    this.ˊ.ʻˋ.smoothScrollTo(0, 0);
                }
            });
        }
    }

    private void ˉॱ() {
        if (this.ʹ && this.ﾟ) {
            this.ʼ.removeMessages(105);
            this.ʼ.sendEmptyMessage(105);
        }
    }

    private String ˊʻ() {
        return "360101";
    }

    private LinkedHashMap<String, String> ˌॱ() {
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("pagename", ॱ(R.string.install_manage));
        linkedHashMap.put("pageid", "customColumn.managercenter");
        linkedHashMap.put("third_id", epr.ˎ().ˏ());
        linkedHashMap.put("service_type", String.valueOf(dgm.ˎ(ॱˋ())));
        linkedHashMap.put("time", String.valueOf(System.currentTimeMillis() - this.ॱ));
        return linkedHashMap;
    }

    public void ˎ(boolean z) {
        if (this.ﾞ != null) {
            Logger.ˎ("ManagerFragment", "tip change:" + z);
            dss.ॱ().ˎ(this.ﾞ.ˎ, z);
        }
    }

    public void d_(int i) {
    }
}
